package com.yanggu.mapreduce.nlineInputformat;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2019/12/15 11:24
 * @description:
 */
public class NLineInputFormatMapper extends Mapper<LongWritable, Text, Text, LongWritable> {

    private Text k = new Text();

    private LongWritable v = new LongWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1. 获取一整行
        String line = value.toString();

        //2. 切割
        String[] splits = line.split(" ");

        //3. 循环写出
        for (String split : splits) {
            k.set(split);
            context.write(k, v);
        }
    }
}
